package com.ddlaw.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.ddlaw.entity.TContractType;
import com.ddlaw.entity.TLawContracts;
import com.ddlaw.service.LawContractService;

@Controller
@RequestMapping(value="contract")
public class ContractController extends BaseController{
	
	@Resource
	LawContractService contractTypeService;
	/***
	 * 法律合同首页
	 * @param model		模型数据
	 * @param type		合同大类型
	 * @param s				合同小类型
	 * @return
	 */
	@RequestMapping(value="list",method=RequestMethod.GET)
	public String contractView(Model model,
			@RequestParam(value="type",defaultValue="0") Integer type,
			@RequestParam(value="s",defaultValue="0") Integer s){
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("contractId", type);
		params.put("typeId", s);
		if(type!=0){
			List<TContractType> contracts = contractTypeService.getByTypeId(type);
			model.addAttribute("type", contracts);
			model.addAttribute("show", 1);
		}
		List<TLawContracts> conList = contractTypeService.getByType(params);
		model.addAttribute("typeId", type);
		model.addAttribute("conList", conList);
		model.addAttribute("s", s);
		return "contract/index";
	}
	
	@RequestMapping("/detail/{contractsId}")
	public String detail(@PathVariable(value = "contractsId") Integer contractsId,Model model){
		TLawContracts contracts = contractTypeService.getDetailById(contractsId);
		contractTypeService.addReadNum(contractsId);
		String downloadUrl = contracts.getFileUrl();
		model.addAttribute("contracts", contracts);
		model.addAttribute("download", downloadUrl);
		return "contract/detail";
	}
}
